mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-10-31 09:43:11 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <p>给定一个字符串 <code>s</code>,统计并返回具有相同数量 <code>0</code> 和 <code>1</code> 的非空(连续)子字符串的数量,并且这些子字符串中的所有 <code>0</code> 和所有 <code>1</code> 都是成组连续的。</p>
 | ||
| 
 | ||
| <p>重复出现(不同位置)的子串也要统计它们出现的次数。</p>
 | ||
|  
 | ||
| 
 | ||
| <p><strong>示例 1:</strong></p>
 | ||
| 
 | ||
| <pre>
 | ||
| <strong>输入:</strong>s = "00110011"
 | ||
| <strong>输出:</strong>6
 | ||
| <strong>解释:</strong>6 个子串满足具有相同数量的连续 1 和 0 :"0011"、"01"、"1100"、"10"、"0011" 和 "01" 。
 | ||
| 注意,一些重复出现的子串(不同位置)要统计它们出现的次数。
 | ||
| 另外,"00110011" 不是有效的子串,因为所有的 0(还有 1 )没有组合在一起。</pre>
 | ||
| 
 | ||
| <p><strong>示例 2:</strong></p>
 | ||
| 
 | ||
| <pre>
 | ||
| <strong>输入:</strong>s = "10101"
 | ||
| <strong>输出:</strong>4
 | ||
| <strong>解释:</strong>有 4 个子串:"10"、"01"、"10"、"01" ,具有相同数量的连续 1 和 0 。
 | ||
| </pre>
 | ||
| 
 | ||
| <p> </p>
 | ||
| 
 | ||
| <p><strong>提示:</strong></p>
 | ||
| 
 | ||
| <ul>
 | ||
| 	<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
 | ||
| 	<li><code>s[i]</code> 为 <code>'0'</code> 或 <code>'1'</code></li>
 | ||
| </ul>
 |